'use strict';
Scene.create('test_env', function() {
	let { screenSize, netmap, CameraMoveingObject } = global_ns;
	let { Node, Spatial, Sprite } = nodes_ns;
	
	let cameraMoveingObject = new CameraMoveingObject(main.camera);
	
	let resizeHandler = e => {
		netmap.size.set(screenSize);
	};


	//===============init===============//
	this.init = () => {
		resizeHandler();
		cvs.on('resize', resizeHandler);
		
		
		let { Terminal } = term_ns;
		let term = new Terminal();
		
		Promise.all([
			fetch('scripts/module.js')
				.then(data => data.text())
				.then(data => term.fs.writeFileSync('module', data)),
			fetch('scripts/main.js')
				.then(data => data.text())
				.then(data => term.fs.writeFileSync('main', data))
		]).then(() => {
			term.cmd('run main');
		});
		
		document.querySelector('.input').addEventListener('search', function() {
			term.cmd(this.value);
			this.value = '';
		});
		
		
		console.log('test_env scene inited');
	};


	//===============update===============//
	this.update = function(dt) {
		//=======prePROCES=======//--vs--//=======EVENTS=======//
		cameraMoveingObject.update(touches, main.camera);
		//==================================================//


		//=======PROCES=======//--vs--//=======UPDATE=======//
		
		//==================================================//


		//==========DRAW==========//--vs--//==========RENDER==========//
		main.ctx.clearRect(0, 0, cvs.width, cvs.height);
		
		netmap.draw(main);
		
		main.save();
		main.fillStyle = '#ffffff';
		main.font = 'bold 15px Arial';
		main.ctx.fillText('FPS: '+(1000/dt).toFixed(2), 20, 20);
		main.restore();
	}; //==============================//


	this.exit = () => console.log('exited');
});


Scene.run('test_env');
